<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$this->setting=$this->plugin_setting('sanset');
	if($this->setting['mid']!=$_SESSION['uid']){
		exi('你不是三方管理员！','error','/index/');
	}
	$isarea=intval($_RQ['isarea']);
	$isxuni=intval($_RQ['isxuni']);
	$return['setting']=$this->plugin_setting('page_setting');
	$params=array('mid'=>$_SESSION['uid']);
	if($isarea){
		$params['level']=16;
	}
	if($isxuni){
		$params['isxuni']=1;
		$return['jiesuannum']=$this->count('commission',array('isxuni'=>1,'mid'=>$_SESSION['uid'],'status'=>1));
	}
	$return['commission_money']=$this->sum('commission',$params,'money');
	if(!$return['commission_money']){
		$return['commission_money']=0;
	}
	$return['commission_total']=$this->count('commission',$params);
	$params['type']=20;
	unset($params['level']);
	$return['jichanum']=$this->count('commission',$params);
	$levels=array();
	/*for($i=0;$i<$this->setting['level'];$i++){
		$level=$i+1;
		$levels[$i]['key']=$level;
		$levels[$i]['title']=$this->setting['levelname'.$level]?:$level.'级';
		$levels[$i]['num']=$this->count('commission',array('mid'=>$_SESSION['uid'],'level'=>$level));
	}*/
	$return['levels']=$levels;
	$return['list']=array();
	$return['params']=array(
		'isarea'=>$isarea,
		'isxuni'=>$isxuni,
		'level'=>1,
		'page'=>1,
	);
	$return['psize']=20;
	set_html('title','分润明细');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('mid'=>$_SESSION['uid']);
	if(intval($_RQ['isarea'])){
		$level=16;
	}else{
		$level=intval($_RQ['level']);
		if(!$level){
			$level=1;
		}
	}
	if($level==20){
		$params['type']=$level;
	}else{
		//$params['level']=$level;
	}
	if(intval($_RQ['isxuni'])){
		$params['isxuni']=1;
		unset($params['level']);
	}
	$return['params']['level']=$level;
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('commission',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['member']=model('core/member')->basic($order['mid']);
		$item['statustitle']=$this->commission_status[$item['status']];
        $item['typetitle']=$this->commission_money_types2[$commission['level']];
        $item['typetitle']=$item['typetitle']?:'其他分润';
	}
	exi($list);
}
?>